package svc.elib.analysis;

import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;

import svc.elib.db.Database;
import svc.elib.db.Paper;
import svc.elib.socnet.Link;
import svc.elib.socnet.Net;
import svc.elib.socnet.SocConstructor;

public class OldestLink {
	
	public static void main(String[] args) 
		throws IOException
	{
		Database db = new Database("eLibData.csv", 1932, 2011);
		System.out.println(db.info());
		SocConstructor soc = new SocConstructor(db);
		Net net = soc.getNet();
	
		Link oldestLink = null;
		int year = Integer.MAX_VALUE;
		
		Iterator<Link> lit = net.getGraph().getEdges().iterator();
		while (lit.hasNext()) {
			Link l = lit.next();
			if (l.getFirstYear() < year) {
				oldestLink = l;
				year = l.getFirstYear();
			}
		}
		
		System.out.println("Year: " + year);
		System.out.println("Link: " + oldestLink.getName());
		System.out.println("Papers in common: ");
		LinkedList<Paper> pl = oldestLink.getPapersInCommon();
		for (Paper p : pl) {
			System.out.println(p.getInfo());
		}
	}

}
